/*************************************************************
 * 
 * CopyRight(c)2007, http://www.moorwind.com/
 * email:ezhung@gmail.com
 * for free, but a email permission would be nice
 * 
 ************************************************************/
package kono.utils.collections
{
	import kono.utils.D2Array;
	
	public class D2ArrayIterator implements Iiterator
	{
		private var _array:D2Array;
		private var xCursor:uint;
		private var yCuror:uint;
		
		public function D2ArrayIterator(data:D2Array)
		{
			_array = D2Array;
			xCursor = yCursor = 0;
		}
		public function hasNext():Boolean
		{
			return (yCursor * _array.width + xCursor < _array.size);
		}
		
		public function next():*
		{
			var current:* = data;
			if(++xCursor == _array.width)
			{
				yCursor++;
				xCursor = 0;
			}
			return current;
		}
		
		public function get data():*
		{
			return _array.getItem(xCursor,yCursor);
		}
		
		public function set data(item:*):void
		{
			_array.addItem(xCursor,yCursor,item);
		}
		
		public function start():void
		{
			xCursor = yCursor = 0;
		}
		
	}
}